
//
// 130228 - AH - Created.
//

package org.japril.gim;

/**
 * <p>
 *   Default implementation of
 *   {@link Item}.
 * </p>
 * @author Arne Halvorsen (AH)
 */
public class DefaultItem implements Item
{
  private final int m_id;
  
  private final String m_type;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param id {@link #getId()}.
   */
  public DefaultItem(int id, String type)
  {
    if (id<0)
    {
      throw new IllegalArgumentException("id<0 : "+id);
    }
    if (type==null)
    {
      throw new NullPointerException("type");
    }
    
    type=type.trim();
    if (type.length()==0)
    {
      throw new IllegalArgumentException("type the empty string");
    }
    
    m_id=id;
    m_type=type;
  }

  // Specified in Item.
  public int getId(){ return m_id; }
  
  // Specified in Item.
  public String getType(){ return m_type; }

  @Override
  public String toString()
  {
    StringBuilder sb=new StringBuilder();
    sb.append("key=").append(m_id).append(", type=").append(m_type);
    return sb.toString();
  }
  
}
